home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / word-count.izs < prev    next >
Text File  |  2005-09-28  |  4KB  |  176 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Word Count 
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>Finally, an easy way to count the number of words that are entered into a form!   <!/DESCRIPTION> 
  7.  
  8. <!CATEGORY>Forms<!/CATEGORY>
  9.  
  10. <!SCRIPT>
  11. <!-- START OF SCRIPT -->
  12.  
  13. <!-- HOW TO INSTALL WORD COUNT:
  14.  
  15.   1.  Copy code into the HEAD section of document
  16.   2.  Put last coding into the BODY section of document  -->
  17.  
  18. <!-- STEP ONE: Add code into HEAD section of document  -->
  19.  
  20. <HEAD>
  21.  
  22. <SCRIPT LANGUAGE="JavaScript">
  23. <!-- Original:  Shawn Seley -->
  24.  
  25.  
  26. <!-- Begin
  27. function CountWords (this_field, show_word_count, show_char_count) {
  28. if (show_word_count == null) {
  29. show_word_count = true;
  30. }
  31. if (show_char_count == null) {
  32. show_char_count = false;
  33. }
  34. var char_count = this_field.value.length;
  35. var fullStr = this_field.value + " ";
  36. var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
  37. var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
  38. var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
  39. var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
  40. var splitString = cleanedStr.split(" ");
  41. var word_count = splitString.length -1;
  42. if (fullStr.length <2) {
  43. word_count = 0;
  44. }
  45. if (word_count == 1) {
  46. wordOrWords = " word";
  47. }
  48. else {
  49. wordOrWords = " words";
  50. }
  51. if (char_count == 1) {
  52. charOrChars = " character";
  53. } else {
  54. charOrChars = " characters";
  55. }
  56. if (show_word_count & show_char_count) {
  57. alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
  58. }
  59. else {
  60. if (show_word_count) {
  61. alert ("Word Count:  " + word_count + wordOrWords);
  62. }
  63. else {
  64. if (show_char_count) {
  65. alert ("Character Count:  " + char_count + charOrChars);
  66.       }
  67.    }
  68. }
  69. return word_count;
  70. }
  71. //  End -->
  72. </script>
  73.  
  74. </HEAD>
  75.  
  76. <!-- STEP TWO: Add code into BODY section of document  -->
  77.  
  78. <BODY>
  79.  
  80. <form>
  81. <textarea cols=40 rows=5 name=x>
  82. </textarea>
  83. <br>
  84. <input type=button value="Count Words" OnClick ="CountWords(this.form.x, true, true);">
  85. </form>
  86.  
  87.  
  88.  
  89. <!-- END OF SCRIPT -->
  90. <!/SCRIPT>
  91.  
  92. <!PREVIEW>
  93. <!-- START OF SCRIPT -->
  94.  
  95.  
  96. <!-- HOW TO INSTALL WORD COUNT:
  97.  
  98.   1.  Copy code into the HEAD section of document
  99.   2.  Put last coding into the BODY section of document  -->
  100.  
  101. <!-- STEP ONE: Add code into HEAD section of document  -->
  102.  
  103. <HEAD>
  104.  
  105. <SCRIPT LANGUAGE="JavaScript">
  106. <!-- Original:  Shawn Seley -->
  107.  
  108.  
  109. <!-- Begin
  110. function CountWords (this_field, show_word_count, show_char_count) {
  111. if (show_word_count == null) {
  112. show_word_count = true;
  113. }
  114. if (show_char_count == null) {
  115. show_char_count = false;
  116. }
  117. var char_count = this_field.value.length;
  118. var fullStr = this_field.value + " ";
  119. var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
  120. var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
  121. var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
  122. var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
  123. var splitString = cleanedStr.split(" ");
  124. var word_count = splitString.length -1;
  125. if (fullStr.length <2) {
  126. word_count = 0;
  127. }
  128. if (word_count == 1) {
  129. wordOrWords = " word";
  130. }
  131. else {
  132. wordOrWords = " words";
  133. }
  134. if (char_count == 1) {
  135. charOrChars = " character";
  136. } else {
  137. charOrChars = " characters";
  138. }
  139. if (show_word_count & show_char_count) {
  140. alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
  141. }
  142. else {
  143. if (show_word_count) {
  144. alert ("Word Count:  " + word_count + wordOrWords);
  145. }
  146. else {
  147. if (show_char_count) {
  148. alert ("Character Count:  " + char_count + charOrChars);
  149.       }
  150.    }
  151. }
  152. return word_count;
  153. }
  154. //  End -->
  155. </script>
  156.  
  157. </HEAD>
  158.  
  159. <!-- STEP TWO: Add code into BODY section of document  -->
  160.  
  161. <BODY>
  162.  
  163. <form>
  164. <textarea cols=40 rows=5 name=x>
  165. </textarea>
  166. <br>
  167. <input type=button value="Count Words" OnClick ="CountWords(this.form.x, true, true);">
  168. </form>
  169.  
  170.  
  171.  
  172. <!-- END OF SCRIPT -->
  173. <!/PREVIEW>
  174.  
  175. <!RELATED>NONE<!/RELATED>
  176.